package com.igeek.shop.web.houtai;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.igeek.shop.entity.User;
import com.igeek.shop.service.shouye.IndexService;
import com.igeek.shop.service.shouye.IndexServiceImp;

public class ManagerialServlet extends HttpServlet {

	/**
	 * 后台登录功能
	 */
	private static final long serialVersionUID = 1L;
	private IndexService service = new IndexServiceImp();
	

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String state = req.getParameter("state");
		if(state.equals("manage")){
			manage(req,resp);
		}else if (state.equals("test")){
			test(req,resp);
		}
	}

	
	private void test(HttpServletRequest req, HttpServletResponse resp) {
		// TODO Auto-generated method stub
	
	}


	private void manage(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String username = req.getParameter("username");
		String password = req.getParameter("password");
		User user = service.queryusername(username,password);
		if(user!=null){
			req.getSession().setAttribute("user", user);
			req.getRequestDispatcher("/admin/home.jsp").forward(req, resp);
		}else{
			req.setAttribute("msg","对不起,账号或密码错误!" );
			req.getRequestDispatcher("/admin/index.jsp").forward(req, resp);
		}
		
	}

	
}
